package com.emagic.manage.mvp.subscribers;

import com.emagic.manage.mvp.views.LoadDataView;
import com.xitaiinfo.library.compat.errorview.ErrorView;

/**
 * TODO 描述该文件做什么
 *
 * @author baoy
 * @version 1.0
 *          Create by 2017/6/27 上午10:54
 */
public abstract class LoadDataSubscriber<T> extends CommonErrorHandlerSubscriber<T> {

    private ErrorView.OnRetryListener onRetryListener;
    private ErrorView.Config config;

    public LoadDataSubscriber(LoadDataView view, ErrorView.OnRetryListener onRetryListener, ErrorView.Config config) {
        super(view);
        this.onRetryListener = onRetryListener;
        this.config = config;
    }

    public LoadDataSubscriber(LoadDataView view) {
        super(view);
    }

    @Override
    public void onCompleted() {
    }

    @Override
    public void onStart() {
        super.onStart();
        mLoadDataView.showLoadingView();
    }

    @Override
    public void onNext(T t) {
        mLoadDataView.onLoadingComplete();
    }

    @Override
    public void onError(Throwable throwable) {
        mLoadDataView.onLoadingComplete();
        mLoadDataView.showErrorView(throwable, config, onRetryListener);
    }

}
